package com.cs171.market.Repository;


import com.cs171.market.entity.Good;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * (Good)商品实体类
 *
 * @author yangyifei
 * @since 2020-05-01 16:33:59
 */
@Repository
public interface GoodRepository extends JpaRepository<Good, Integer> {
    /**
     * 根据展示部位和展示类别输出数据库所有数据
     * @param part：热卖榜单还是精选生鲜
     * @param type：果蔬还是海鲜
     * @return 数据库对应的多条数据
     */
    // hql是面向对象的查询，而不是面向数据库表的查询，因此在hql语句中的对象名必须与实体类的类名一致，严格区分大小写，如本例Good
    @Query("select t.gid as id,t.gname as descp ,t.gprice as price,t.gimg as imgUrl from Good t where t.gdesc=?1 and t.gtype=?2 ")
    List<Map<String, Object>> getHeaderJsonAboutGoods(String part, String type);
    @Query("select t.gid as id,t.gname as descp ,t.gprice as price,t.gimg as imgUrl from Good t where t.gtype=?1 ")
    List<Map<String, Object>> getClassifyJsonAboutGoods(String type);
    @Query("select t.gid as id,t.gname as descp ,t.gprice as price,t.gimg as imgUrl from Good t where t.gdesc=?1 ")
    List<Map<String, Object>> recommendJsonAboutGoods(String part);
}
